//
//  WQStatusOriginalView.swift
//  WeiBo
//
//  Created by 张德华 on 7/24/16.
//  Copyright © 2016 ZhangDeHua. All rights reserved.
//

import UIKit
import SnapKit

class WQStatusOriginalView: UIView {

    
    /**记录当前原创微博的底部约束*/
    var orginalViewBottomConstraint:Constraint?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = RandomColor()
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    
 
    var statusViewModel: WQStatusViewModel? {
        didSet{
            
            headIamgeView.wq_setImage(statusViewModel?.status?.user?.profile_image_url, placeholderName: "avatar_default")
            nameLabel.text = statusViewModel?.status?.user?.name
            timeLabel.text = statusViewModel?.sinaTimeStr
            sourceLabel.attributedText = statusViewModel?.sourceAttr
            memberImageView.image = statusViewModel?.memberImage
            avatarImageView.image = statusViewModel?.avatarImage
            contentLabel.text = statusViewModel?.status?.text
            
            
            ///------ 卸载约束
            
        }
    }
    
    
    func setupUI() {
        
        // MARK: - ************添加控件
        addSubview(headIamgeView)
        addSubview(nameLabel)
        addSubview(memberImageView)
        addSubview(avatarImageView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(contentLabel)
        
        
        
        ///------ 头像
        headIamgeView.snp_makeConstraints { (make) in
            make.top.leading.equalTo(10)
            make.size.equalTo(CGSize(width: 35, height: 35))
        }
        ///------ 昵称
        nameLabel.snp_makeConstraints { (make) in
            make.leading.equalTo(headIamgeView.snp_trailing).offset(10)
            make.top.equalTo(headIamgeView)
        }
        ///------ 会员等级
        memberImageView.snp_makeConstraints { (make) in
            make.leading.equalTo(nameLabel.snp_trailing).offset(10)
            make.centerY.equalTo(nameLabel)
            make.size.equalTo(CGSize(width: 10, height: 10))
        }
        ///------ 认证
        avatarImageView.snp_makeConstraints { (make) in
            make.centerX.equalTo(headIamgeView.snp_trailing)
            make.centerY.equalTo(headIamgeView.snp_bottom)
        }
        ///------ 发布时间
        timeLabel.snp_makeConstraints { (make) in
            make.leading.equalTo(nameLabel.snp_leading)
            make.bottom.equalTo(headIamgeView)
        }
        ///------ 信息来源
        sourceLabel.snp_makeConstraints { (make) in
            make.leading.equalTo(timeLabel.snp_trailing).offset(10)
            make.bottom.equalTo(timeLabel)
        }
        ///------ 内容
        contentLabel.snp_makeConstraints { (make) in
            make.leading.equalTo(headIamgeView.snp_leading)
            make.width.equalTo(SCREENSIZE.width - 20)
            make.top.equalTo(headIamgeView.snp_bottom).offset(10)
        }
        ///------ 配图
//        pictureView.snp_makeConstraints { (make) in
//            make.top.equalTo(contentLabel.snp_bottom).offset(statusCellMargin)
//// TODO: - 配图约束
//            //            make.leading.equalTo(SCREENSIZE.width - ()
//        }
        self.snp_makeConstraints { (make) in
            make.bottom.equalTo(contentLabel.snp_bottom).offset(10)
        }
        
        
    }
    
    // MARK: - ************懒加载
    ///------ 头像
    private lazy var headIamgeView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    ///------ 昵称
    private lazy var nameLabel: UILabel = UILabel(wq_text: "wwww", fontSize: 14, textColor: UIColor.redColor(), alignment: NSTextAlignment.Left)
    ///------ 会员等级
    private lazy var memberImageView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_expired"))
    ///------ 认证
    private lazy var avatarImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    ///------ 发布时间
    private lazy var timeLabel: UILabel = UILabel(wq_text: "2小时前", fontSize: 12, textColor: UIColor.brownColor())
    ///------ 信息来源
    private lazy var sourceLabel: UILabel = UILabel(wq_text: "来自 火星", fontSize: 12, textColor: UIColor.brownColor())
    ///------ 内容
    private lazy var contentLabel: UILabel = UILabel(wq_text: "来自 火星", fontSize: 12, textColor: UIColor.blackColor())
    ///------ 配图
    private lazy var pictureView: WQStatusPictureView = WQStatusPictureView()
    
    
    
    
}
